package cn.qqncn.service.impl;

import cn.qqncn.mapper.CapsuleMapper;
import cn.qqncn.entity.Capsule;
import cn.qqncn.service.CapsuleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zkw
 * @Description TODO
 * @createTime 2021年05月08日 15:14:00
 */
@Service
public class CapsuleServiceImpl implements CapsuleService {
    @Resource
    CapsuleMapper capsuleMapper;

    @Override
    public boolean addCapsule(Capsule capsule) {
        int insert = capsuleMapper.insert(capsule);
        return insert>0?true:false;
    }

    @Override
    public List<Capsule> getTodayCapsule() {
        return capsuleMapper.selectTodayCapsule();
    }

    @Override
    public boolean updateState(Integer id,Integer state) {
        Capsule capsule = new Capsule();
        capsule.setId(id);
        capsule.setStatus(state);
        QueryWrapper<Capsule> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        int update = capsuleMapper.update(capsule, queryWrapper);
        return update>=1?true:false;
    }
}
